#!/usr/bin/env python3
# -*- coding: utf-8 -*-
########################################################################
#
# Copyright (c) 2023 Zhiyong Lin. All Rights Reserved
#
########################################################################
'''
@File    :   weather_client.py
@Time    :   2025/10/20 17:50:00
@Author  :   lzy2lcy 
@Version :   1.0
@Desc    :   Weather API client
'''
import requests
import config

def get_weather(city: str) -> dict:
    """调用天气API获取天气信息"""
    api_key = config.WEATHER_API_KEY
    if not api_key:
        raise ValueError("WEATHER_API_KEY is not configured")
    
    url = f"http://api.weatherapi.com/v1/current.json?key={api_key}&q={city}&aqi=no"
    
    try:
        response = requests.get(url, timeout=10)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as e:
        raise Exception(f"Failed to get weather data: {str(e)}")
    except ValueError as e:
        raise Exception(f"Invalid weather data received: {str(e)}")